#!/usr/bin/env bash
source ./env.sh
function cmd() {
    echo "$1"
    $1
}

# shellcheck disable=SC2154
docker build  --no-cache -t $images .
#docker build   -t $images .
# shellcheck disable=SC2181
if [[ $? -eq 0 ]];then
  # shellcheck disable=SC2154
  id=$(docker images | grep $name | grep $ver  | awk '{print $3}' | sed -n 1p)
  # shellcheck disable=SC2154
  cmd "docker tag $id $latest"
  # shellcheck disable=SC2154
  echo "$1"
  if [[ "$1" == "p" ]];then
      echo "取消推送镜像..."
  else
    cmd "docker push $latest"
    cmd "docker push $images"
  fi
else
  echo  "构建失败"
fi
